package com.yjck.fm.login.action;



import java.io.ByteArrayInputStream;
import java.io.InputStream;

import com.opensymphony.xwork2.ActionSupport;
import com.yjck.fm.login.bean.User;
import com.yjck.fm.login.service.RegisterService;
import com.yjck.fm.util.MD5Utils;


@SuppressWarnings("serial")
public class RegisterAction extends ActionSupport {
	private User user;
	private RegisterService registerService;
	private InputStream inputStream;

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setRegisterService(RegisterService registerService) {
		this.registerService = registerService;
	}

	@Override
	public String execute() throws Exception {	
		//对密码进行md5加密
		user.setPasswd(MD5Utils.getMD5Str(user.getPasswd()));		
		boolean flag = registerService.register(user);
		if(flag){
			inputStream = new ByteArrayInputStream("success".getBytes("UTF-8"));
		}else{
			inputStream = new ByteArrayInputStream("fail".getBytes("UTF-8"));
		}
		return "register";
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
